<script type="text/javascript">
    function submitMiscForm() {
        $.ajax({
            url:'index.php?r=contractMonitoringMisc/update&contractid=' + contractid,

            type:'post',
            data:$('#miscForm').serialize(),
            success:function (data) {
                alert('Data Saved');

            }
        });
    }
</script>

<div class="form">

    <?php echo CHtml::form('', '', array('id' => 'miscForm')); ?>
    <?php
    $answersList = CHtml::listData(ContractMonitoringMisc::model()->findAll("contractid = '$model->contractid'"), 'questionid', 'answer');
    $mainQuestions = ContractMiscQuestions::model()->findAll('groupid=1')
    ?>

    <?php foreach ($mainQuestions as $question): ?>
    <div class="row">
        <?php echo CHtml::label($question->question, ''); ?>
        <?php if (isset($answersList[$question->id])) {
        echo CHtml::textField("Answers[$question->id][answer]", $answersList[$question->id]);
    } else {
        echo CHtml::textField("Answers[$question->id][answer]", '');
    }

        ?>
    </div>
    <?php endforeach; ?>
    <div class="row">
        <h1> Open/Close </h1>
    </div>
    <?php
    $secondGroup = ContractMiscQuestions::model()->findAll('groupid=2');
    foreach ($secondGroup as $question): ?>
        <div class="row">
            <?php echo CHtml::label($question->question, ''); ?>
            <?php if (isset($answersList[$question->id])) {
            echo CHtml::textField("Answers[$question->id][answer]", $answersList[$question->id]);
        } else {
            echo CHtml::textField("Answers[$question->id][answer]", '');
        }

            ?>
        </div>
        <?php endforeach; ?>
    <div class="row">
        <h1> Test Monitoring </h1>
    </div>
    <?php
    $thirdGroup = ContractMiscQuestions::model()->findAll('groupid=3');
    foreach ($thirdGroup as $question): ?>
        <div class="row">
            <?php echo CHtml::label($question->question, ''); ?>
            <?php if (isset($answersList[$question->id])) {
            echo CHtml::textArea("Answers[$question->id][answer]", $answersList[$question->id], array('rows' => 6, 'cols' => 50));
        } else {
            echo CHtml::textArea("Answers[$question->id][answer]", '', array('rows' => 6, 'cols' => 50));
        }

            ?>
        </div>
        <?php endforeach; ?>
    <div class="row">
        <h1> Instructions/Procedures</h1>
    </div>
    <?php
    $fourGroup = ContractMiscQuestions::model()->findAll('groupid=4');
    foreach ($fourGroup as $question): ?>
        <div class="row">
            <?php echo CHtml::label($question->question, ''); ?>
            <?php if (isset($answersList[$question->id])) {
            echo CHtml::textArea("Answers[$question->id][answer]", $answersList[$question->id]);
        } else {
            echo CHtml::textArea("Answers[$question->id][answer]", '', array('rows' => 6, 'cols' => 50));
        }

            ?>
        </div>
        <?php endforeach; ?>

    <div class="row buttons">
        <input type="button" onclick="submitMiscForm(); return false;" value="submit"/>
    </div>

    <?php echo CHtml::endForm(); ?>

</div><!-- form -->